package cn.admin.configcenter.registry.pojo;

public final class QueryResult<T> {

    private final int code;
    private final String message;
    private final boolean success;
    private final T data;

    private QueryResult(Builder<T> builder) {
        this.code = builder.code;
        this.message = builder.message;
        this.success = builder.success;
        this.data = builder.data;
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public T getData() {
        return this.data;
    }

    public boolean isSuccess() {
        return this.success;
    }

    public static class Builder<T> {

        private int code;
        private String message;
        private boolean success;
        private T data;

        public Builder(int code,String message) {

            this.code = code;
            if (code == 200) {
                this.success = true;
            } else {
                this.success = false;
            }
            this.message = message;
        }

        public Builder<T> setData(T data) {
            this.data = data;
            return this;
        }

        public QueryResult<T> build() {
            return new QueryResult<>(this);
        }

    }

}
